package com.lagou.controller;

import com.lagou.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("code")
public class CodeController {

    @Autowired
    private CodeService codeService;


    /**
     * 生成验证码，随机六位数
     * @param email
     * @return
     */
    @GetMapping("/create/{email}")
    public Boolean createCode(@PathVariable("email") String email) {
        return codeService.createCode(email);
    }

    /**
     * 验证code是否合法
     * @param email
     * @param code
     * @return
     */
    @GetMapping("/validate/{email}/{code}")
    public String validateCode(@PathVariable("email") String email,@PathVariable("code") String code) {
        return codeService.validateCode(email,code);
    }
}
